package wechat

import (
	"gddgame.cc/galaxy/binocle"
	. "gddgame.cc/galaxy/common/dsl/db"
	. "gddgame.cc/galaxy/common/dsl/web"
	"gddgame.cc/galaxy/server/composer"
)

const PluginName = "wechat"

func init() {
	RegisterPlugin(PluginProvider{
		Name: PluginName,

		OnInit: func(builder composer.Builder, core binocle.CoreClient) error {
			AddTable(&Table{
				Model: WechatRobotModel,
			})
			AddTable(&Table{
				Model: WechatMessageModel,
			})
			return nil
		},
		BindRouter: BindRouter,
	})
}

func BindRouter(builder composer.Builder, core binocle.CoreClient, r *SwaggerRouter) {
	// 接收微信消息
	r.Put("/wechat", Swagger{
		Controller: ReceiveWechat,
		Params: []Param{
			{Name: "talker", In: Body},
			{Name: "message", In: Body},
		},
		Response: ApiResponse,
	})
	// 返回微信消息
	r.Get("/wechat", Swagger{
		Controller: PopWechat,
		Params:     []Param{},
		Response:   ApiResponse,
	})
}
